<template>
  <div class="module5">
    <div class="module5-head">一周天气</div>
    <div class="module5-content">
      <div class="module5-top">
        <div
          class="module5-top-h"
          v-for="(item, index) in weaterData"
          :key="index"
        >
          <div style="color: white">{{ item.week }}</div>
          <img
            :src="item.iconUrl"
            alt=""
            style="width: 46px; height: 46px; margin-top: 10px"
          />
        </div>
      </div>
      <div style="height: 40%; width: 100%">
        <WeaterChartline :sourceData="weaterData"></WeaterChartline>
      </div>
      <div class="module5-top">
        <div
          class="module5-top-h"
          v-for="(item, index) in weaterData"
          :key="index"
        >
          <img
            :src="item.iconUrl"
            alt=""
            style="width: 46px; height: 46px; margin-top: 10px"
          />
          <div style="color: white">{{ item.fx }}</div>
          <div style="color: white">{{ item.fl }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
import { getWeatherInfo } from '@/api/index.js'
import WeaterChartline from '../chartmodule/weaterChartline.vue'

import weather_1 from '@/assets/img/weather1.png' // 晴
import weather_2 from '@/assets/img/weather2.png' // 小雨
import weather_3 from '@/assets/img/weather3.png' // 打雷
import weather_4 from '@/assets/img/weather4.png' // 雪
import weather_5 from '@/assets/img/weather5.png' // 大雨

const weaterData = ref([])
const weaterIcon = {
  1: weather_1,
  2: weather_2,
  3: weather_3,
  4: weather_4,
  5: weather_5
}
onMounted(() => {
  getWeatherInfo({
    cityId: '101191304'
  }).then((res) => {
    if (res.code === 200) {
      const data = res.data
      const result = data.slice(0, 7)
      result.forEach((item) => {
        item.iconUrl = weaterIcon[item.icon]
      })
      weaterData.value = result
    }
  })
})
</script>
<style scoped lang="scss">
.module5 {
  width: 100%;
  height: 100%;
  padding-top: 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-direction: column;
  .module5-head {
    width: 100%;
    max-width: 405px;
    height: 33px;
    background: url('@/assets/img/card-head.png') no-repeat center;
    background-size: 100% 100%;
    font-family: FZZYJW;
    font-weight: normal;
    font-size: 20px;
    color: #c3ff55;
    line-height: 24px;
    padding-left: 42px;
  }
  .module5-content {
    flex: 1;
    width: 100%;
    padding: 16px;
    box-sizing: border-box;
    overflow: hidden;
    .module5-top {
      padding: 0 16px;
      display: flex;
      box-sizing: border-box;
      height: 30%;
      justify-content: space-between;
      .module5-top-h {
        display: flex;
        flex-direction: column;
        align-items: center;
      }
    }
  }
}
</style>
